<?php
namespace Common\Controller;

use Think\Controller;
class StaticController extends Controller{
    private $customer_id = 1;

    //发送消息
    public function sendBatch(){
    	$BatchLog = D('MessageBatchLog');
    	//待发送消息数据
    	$msg_data = $BatchLog->where("is_send='2'")->select();
    	//调用接口发送消息
    	$token = D('Customer')->getToken($this->customer_id);
        $Api = D('Api');
    	foreach ($msg_data as $key=>$val){
    		$Api->sendWxMsg($token,$val['fromuser'],$val['msg_content']);
    		$BatchLog->save(array('id'=>$val['id'],'is_send'=>'1'));
    	}
    	sleep(2);
    }
    //同步粉丝信息
	public function syncMemberInfo(){
		$model = D('Member');
		$api = D('Api');
		$access_token = D('Customer')->getToken($this->customer_id);
		$members = $model->where(array('customer_id'=>$this->customer_id,'is_sync'=>'2'))->limit(60)->select();
		foreach ($members as $val){
			$userInfo = $api->getUserInfo($access_token,$val['fromuser']);//获取用户基本信息
			if(!empty($userInfo['nickname'])){
				$rowMem['status'] = $userInfo['subscribe'];
				$rowMem['group_id'] = $userInfo['groupid'];
				$rowMem['nickname'] = $userInfo['nickname'];
				$rowMem['headimgurl'] = $userInfo['headimgurl'];
				$rowMem['sex'] = $userInfo['sex'];
				$rowMem['language'] = $userInfo['language'];
				$rowMem['country'] = $userInfo['country'];
				$rowMem['province'] = $userInfo['province'];
				$rowMem['city'] = $userInfo['city'];
				if($userInfo['subscribe']=='1')$rowMem['subscribe_time'] = $userInfo['subscribe_time'];
					
				$rowMem['id'] = $id;
				$rowMem['is_sync'] = '1';
				$model->save($rowMem);
			}
		}
		sleep(2);
	}
}
